package co.fitstart.admin.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.persistence.annotation.Execute;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.market.CreditRecord;
import co.fitstart.entity.market.InvitationStatus;
import co.fitstart.entity.market.MarketCourse;
import co.fitstart.entity.market.MarketCourseRound;
import co.fitstart.entity.market.MarketInvitationRecord;
import co.fitstart.entity.market.MarketRecommendRecord;
import co.fitstart.entity.market.MarketWechatImage;
import co.fitstart.entity.market.template.MarketBatchCoursewareTemplate;
import co.fitstart.entity.market.template.MarketCoursewareTemplate;
import co.fitstart.entity.market.template.MarketDailyCoursewareTemplate;
import co.fitstart.entity.market.template.MarketMonthlyCoursewareTemplate;
import co.fitstart.entity.user.User;

@Dynamic("hibernate")
public interface MarketCoursewareDao {
    
    /**
     * 
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM MarketCourse WHERE disabled = false")
    public List<MarketCourse> listMarketCourse(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param user
     * @return
     */
    @Query("FROM MarketCourseRound WHERE disabled = false AND user = :user")
    public MarketCourseRound loadMarketCourseRound(@Variable("user") User user);
    
    /**
     * 
     * @param course
     * @return
     */
    @Query("FROM MarketMonthlyCoursewareTemplate WHERE disabled = false AND course = :course ORDER BY sorting ASC")
    public List<MarketMonthlyCoursewareTemplate> listMonthlyCoursewareTemplate(@Variable("course") MarketCourse course);
    
    /**
     * 
     * @param monthly
     * @return
     */
    @Query("FROM MarketBatchCoursewareTemplate WHERE disabled = false AND monthly = :monthly ORDER BY sorting ASC")
    public List<MarketBatchCoursewareTemplate> listMarketBatchCoursewareTemplate(@Variable("monthly") MarketMonthlyCoursewareTemplate monthly);
    
    /**
     * 
     * @param batch
     * @return
     */
    @Query("FROM MarketDailyCoursewareTemplate WHERE disabled = false AND batch = :batch ORDER BY sorting ASC")
    public List<MarketDailyCoursewareTemplate> listMarketDailyCoursewareTemplate(@Variable("batch") MarketBatchCoursewareTemplate batch);
    
    /**
     * 
     * @param daily
     */
    @Execute("UPDATE MarketCoursewareTemplate SET disabled = true WHERE disabled = false AND daily = :daily")
    public void updateMarketCoursewareTemplate(@Variable("daily") MarketDailyCoursewareTemplate daily);
    
    /**
     * 
     * @param course
     * @param monthly
     * @return
     */
    @Query("FROM MarketMonthlyCoursewareTemplate WHERE disabled = false AND course = :course AND sorting = :months")
    public MarketMonthlyCoursewareTemplate loadMarketMonthlyCoursewareTemplate(@Variable("course") MarketCourse course, @Variable("months") int months);

    
    /**
     * 
     * @param monthly
     * @param weeks
     * @return
     */
    @Query("FROM MarketBatchCoursewareTemplate WHERE disabled = false AND monthly = :monthly AND sorting = :weeks")
    public MarketBatchCoursewareTemplate loadMarketBatchCoursewareTemplate(@Variable("monthly") MarketMonthlyCoursewareTemplate monthly, @Variable("weeks") int weeks);

    /**
     * 
     * @param daily
     * @return
     */
    @Query("FROM MarketCoursewareTemplate WHERE disabled = false AND daily = :daily")
    public List<MarketCoursewareTemplate> listMarketCoursewareTemplate(@Variable("daily") MarketDailyCoursewareTemplate daily);
    
    /**
     * 
     * @param user
     * @return
     */
    @Query("FROM CreditRecord WHERE user = :user")
    public List<CreditRecord> listCreditRecord(@Variable("user") User user);
    
    /**
     * 
     * @param course
     * @return
     */
    @Query("FROM MarketWechatImage WHERE disabled = false AND course = :course")
    public MarketWechatImage loadMarketWechatImage(@Variable("course") MarketCourse course);
    
    /**
     * 
     * @param inviter
     * @param status
     * @return
     */
    @Query("FROM MarketInvitationRecord WHERE inviter = :inviter AND status = :status")
    public List<MarketInvitationRecord> listInvitationRecord(@Variable("inviter") String inviter, @Variable("status") InvitationStatus status);
    
    /**
     * 
     * @param inviter
     * @return
     */
    @Query("FROM MarketRecommendRecord WHERE recommender = :recommender")
    public List<MarketRecommendRecord> listRecommendRecord(@Variable("recommender") String inviter);
}
